<template>
  <!-- <div class="app-container"> -->
    <div class="app-container home">
    <div style="margin-bottom: 10px; margin-top: 0px;">
      <h3>内容同步配置</h3>
    <el-table v-loading="loading" :data="contentSynchList" @selection-change="handleSelectionChange">
      <el-table-column label="内容同步" align="center" prop="name" />
      <el-table-column label="同步状态" align="center" prop="intValue" />
      <el-table-column label="运营商" align="center" prop="value1" />
      <el-table-column label="服务地址" align="center" prop="value2" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:contentSynch:edit']"
          >修改</el-button>
        </template>
      </el-table-column>
    </el-table>
    </div>
    <!-- 添加或修改内容同步管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入名称" disabled=""/>
        </el-form-item>
        <el-form-item label="同步状态" prop="intValue">
          <el-radio-group v-model="form.intValue">
            <el-radio
              v-for="dict in dict.type.sys_notice_status"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="运营商" prop="value1">
          <el-input v-model="form.value1" placeholder="请输入运营商" />
        </el-form-item>
        <el-form-item label="服务地址" prop="value2">
          <el-input v-model="form.value2" placeholder="请输入服务地址" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>



        <div style="margin-bottom: 10px; margin-top: 0px;">
      <h3>版本同步配置</h3>
    <el-table v-loading="loading" :data="contentSynchListVersion" @selection-change="handleSelectionChange">
      <el-table-column label="版本同步" align="center" prop="name" />
      <el-table-column label="同步状态" align="center" prop="intValue" />
      <el-table-column label="最新版本" align="center" prop="value1" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdateVersion(scope.row)"
            v-hasPermi="['system:contentSynch:edit']"
          >修改状态</el-button>
        </template>
      </el-table-column>
    </el-table>
    </div>

    <el-dialog :title="title" :visible.sync="openVersion" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入名称" disabled=""/>
        </el-form-item>
         <el-form-item label="同步状态" prop="intValue">
          <el-radio-group v-model="form.intValue">
            <el-radio
              v-for="dict in dict.type.sys_notice_status"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="当前最新版本" prop="value1">
          <el-input v-model="form.value1"  disabled=""/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancelVersion">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listContentSynch,listContentSynchVersion, getContentSynch, delContentSynch, addContentSynch, updateContentSynch } from "@/api/system/contentSynch";

export default {
  name: "ContentSynch",
  dicts: ['sys_notice_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 内容同步管理表格数据
      contentSynchList: [],
      contentSynchListVersion: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openVersion: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        intValue: null,
        value1: null,
        value2: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询内容同步管理列表 */
    getList() {
      this.loading = true;
      listContentSynch(this.queryParams).then(response => {
        this.contentSynchList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
       listContentSynchVersion(this.queryParams).then(response => {
        this.contentSynchListVersion = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
        cancelVersion() {
      this.openVersion = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        intValue: null,
        value1: null,
        value2: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加内容同步管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getContentSynch(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改内容同步管理";
      });
    },

    handleUpdateVersion(row){
            this.reset();
      const id = row.id || this.ids
      getContentSynch(id).then(response => {
        this.form = response.data;
        this.openVersion = true;
        this.title = "修改版本同步状态";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateContentSynch(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.openVersion = false;
              this.getList();
            });
          } else {
            addContentSynch(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.openVersion = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除内容同步管理编号为"' + ids + '"的数据项？').then(function() {
        return delContentSynch(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/contentSynch/export', {
        ...this.queryParams
      }, `contentSynch_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
